# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=("aspell" "aspell-devel")
pkgver=0.60.6.1
pkgrel=1
pkgdesc=" a Free and Open Source spell checker (libraries)"
arch=('i686' 'x86_64')
url="http://aspell.net/"
license=('LGPL')
groups=('libraries')
makedepends=('gcc' 'gettext-devel' 'libiconv-devel' 'ncurses-devel')
options=()
source=("https://ftp.gnu.org/gnu/aspell/${pkgname}-${pkgver}.tar.gz"{,.sig}
        "msys-platform.patch"
        "aspell-noundefined.patch"
        "aspell-so2dll.patch"
        "aspell-fileno.patch")
sha256sums=('f52583a83a63633701c5f71db3dc40aab87b7f76b29723aeb27941eff42df6e1'
            'SKIP'
            'ed9a09ee29c031b979b76a9146c60fadd8c591b072f09c1a29fd640be0bbca8a'
            '5188d1443b04c095261b3fe01f77a9235ca4b3c5c35caa87167a5507a30f6bee'
            '9b9e4300d35a92f029c098da7001235d1dd6aeb03a854591afd84606b5cd257b'
            '8054609ba63038c7f488782a1f80ed31ba1fe18ded842707702ad08793903c7b')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p1 -i ${srcdir}/msys-platform.patch
  patch -p1 -i ${srcdir}/aspell-noundefined.patch
  patch -p1 -i ${srcdir}/aspell-so2dll.patch
  patch -p1 -i ${srcdir}/aspell-fileno.patch
  autoreconf -ivf
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure --prefix=/usr --build=${CHOST} --enable-static
  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make -k check
}

package_aspell() {
  depends=("gcc-libs" "gettext" "libiconv" "ncurses")

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/

  mkdir -p ${pkgdir}/usr/lib/aspell-0.60
  cp -rf ${srcdir}/dest/usr/lib/aspell-0.60 ${pkgdir}/usr/lib/

  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_aspell-devel() {
  pkgdesc="Aspell headers and libraries (development)"
  groups=('development')
  depends=("aspell=${pkgver}" "gettext-devel" "libiconv-devel" "ncurses-devel")

  mkdir -p ${pkgdir}/usr/lib
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -f ${srcdir}/dest/usr/lib/*.a ${pkgdir}/usr/lib
}
